<?php
header("content-type:text/html; charset=utf-8");
$type=$_GET['type'];

if($type=='修改信息'){
  xgxx();
}else if($type=='修改密码'){
   xgmm();
}
else{ 
    header("refresh:1;url=subper.php");
    die("非法进入！");
   
}
?>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改界面</title>
</head> <style>
        .main{
            width:50%;
            height:400px;
            border: 2px solid orange;
            margin:60px auto;
            line-height:50px;
            padding-left: 30px;
        }
        @media screen and (max-width:500px){
            .main{
            width:85%;
            height:400px;
            border: 2px solid orange;
            margin:60px auto;
            line-height:50px;
            padding-left:30px;
            }
        }
    </style>
    <script>
        function a(){
           var a=document.getElementById('a1').value;
           var b=document.getElementById('a2').value;
           if(a!=b){
               alert("两次密码输入不一致！");
               return false;
           }
           
        }
        </script>
<body>
           <?php
           function xgxx(){
            $name=$_GET['name'];
            echo " <div class=main>
            <h2>修改信息</h2>
            <form action='#' method='POST'>
                 邮箱地址：<input type=text name=updateemail size=20 required placeholder='请输入新的邮箱地址' /><br/>
                 手机号码：<input type=text name=updatephto  size=20 required placeholder='请输入新的手机号码' /><br/>
                 <input type='submit' name='submit' value=修改>
                 &nbsp;&nbsp;<a href='subper.php'>返回</a>
             </form>";
             if($_POST['submit']){
            $email=$_POST['updateemail'];
            $phto=$_POST['updatephto'];
         
          $serverLink=@mysql_connect("localhost","root","root") or die("连接服务器失败！程序中断");
          mysql_query("'set names 'utf-8'");
          $dbLink=@mysql_select_db("supermarket") or die("打开supermarket数据库失败！程序中断");
          $updatesql="update admsign set email='$email',phtonumber='$phto' where admname='$name'";
          mysql_query($updatesql);
          $fhxx1=mysql_affected_rows();
          if($fhxx1>'0'){
            echo  "修改成功"."<br/>";
            echo "新邮箱为：".$email." ";
            echo "新手机号为：".$phto." ";
          }else{
              echo "修改失败";
          }

        }
        echo "</div>";
           }
           function xgmm(){
            $name=$_GET['name'];
            echo " <div class=main>
            <h2>修改密码</h2>
            <form action='#' method='POST' onsubmit='return a()' >
                 旧密码：<input type=text name=password size=20 required  placeholder='请输入旧的密码' /><br/>
                 新密码：<input type=text name=updatpassword size=20 id=a1 required placeholder='请输入新的密码' /><br/>
                 重新输入新密码：<input type=text name=updatpassword2  id=a2 size=20 required placeholder='再次输入新的密码' /><br/>
                 <input type='submit' name='submit' value=修改>
                 &nbsp;&nbsp;<a href='subper.php'>返回</a>
             </form>";
             if($_POST['submit']){
                $password=$_POST['password'];
                $updatepassword=$_POST['updatpassword'];
                $updatepassword2=$_POST['updatpassword2'];
                $serverLink=@mysql_connect("localhost","root","root") or die("连接服务器失败！程序中断");
                mysql_query("'set names 'utf-8'");
                $dbLink=@mysql_select_db("supermarket") or die("打开supermarket数据库失败！程序中断");
            
                $selectsql="select * from admsign where admname='$name' and password='$password'"; 
               $a=mysql_query($selectsql);           
                $fhxx1=mysql_affected_rows();
            
                if($fhxx1>'0'){
                    $updatesql2="update admsign set password=$updatepassword2 where admname='$name'";
                    mysql_query($updatesql2);
                    if(mysql_affected_rows()>'0'){
                        echo "修改成功";
                        echo "新密码为：". $updatepassword2;
                    }

                }else{
                    echo "输入的旧密码不正确！";
                }
           }
           echo "</div>";
        }
      
           ?>
    
        </body>